#include "./../includes/palindromo.h"

/**************************************
 * 
 *  Public methods
 * 
 * ************************************/
palindrom::palindrom( )
{
	this->wordPilha = new pilha<char>;
}

palindrom::palindrom( std::string& _word)
{
	this->wordPilha = new pilha<char>;
	this->setWord(_word);
}

palindrom::palindrom( char* _word)
{
	this->wordPilha = new pilha<char>;
	this->setWord(_word);
}

palindrom::~palindrom()
{
	delete this->wordPilha;
}

void
palindrom::setWord (std::string& _word)
{
	this->word = _word;
	
	for(std::string::iterator counter = word.begin(); counter != word.end(); counter++)
	{
		this->wordPilha->push( *counter);
	}
}

void
palindrom::setWord ( const char* _word)
{
 	std::string
 	temp = _word;
 
 	this->setWord(temp);
}

const bool
palindrom::isPalindrom()
{
	return this->compareStr();
}

/*************************************
 * 
 *  Protected methods
 * 
 * ***********************************/

const bool
palindrom::compareStr()
{
	std::string
	reverseWord;
	
	while (! this->wordPilha->isEmpty())
	{
		reverseWord.push_back( this->wordPilha->getInfo());
		
		this->wordPilha->pop();
	}
	
	if(this->word == reverseWord)
		return true;
	return false;
}
